package com.luyuan.web.controller.gallery;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luyuan.common.annotation.Log;
import com.luyuan.common.core.controller.BaseController;
import com.luyuan.common.core.domain.AjaxResult;
import com.luyuan.common.enums.BusinessType;
import com.luyuan.common.utils.poi.ExcelUtil;
import com.luyuan.gallery.domain.ExhiComment;
import com.luyuan.gallery.service.IExhiCommentService;
import com.luyuan.common.core.page.TableDataInfo;

/**
 * 评论Controller
 * 
 * @author luyuan
 * @date 2025-11-10
 */
@RestController
@RequestMapping("/gallery/comment")
public class ExhiCommentController extends BaseController {
    @Autowired
    private IExhiCommentService exhiCommentService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExhiComment exhiComment) {
        startPage();
        List<ExhiComment> list = exhiCommentService.selectExhiCommentList(exhiComment);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:export')")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExhiComment exhiComment) {
        List<ExhiComment> list = exhiCommentService.selectExhiCommentList(exhiComment);
        ExcelUtil<ExhiComment> util = new ExcelUtil<ExhiComment>(ExhiComment.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(exhiCommentService.selectExhiCommentById(id));
    }

    /**
     * 新增评论
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:add')")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExhiComment exhiComment) {
        return toAjax(exhiCommentService.insertExhiComment(exhiComment));
    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExhiComment exhiComment) {
        return toAjax(exhiCommentService.updateExhiComment(exhiComment));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(exhiCommentService.deleteExhiCommentByIds(ids));
    }

    /**
     * 评论审核接口
     */
    @PreAuthorize("@ss.hasPermi('gallery:comment:review')")
    @Log(title = "评论审核", businessType = BusinessType.UPDATE)
    @PostMapping("/review")
    public AjaxResult review(@RequestBody ExhiComment exhiComment) {
        // 确保只更新状态和备注字段，避免其他字段被意外修改
        ExhiComment updateParam = new ExhiComment();
        updateParam.setId(exhiComment.getId());
        updateParam.setStatus(exhiComment.getStatus());
        updateParam.setRemark(exhiComment.getRemark());
        return toAjax(exhiCommentService.updateExhiComment(updateParam));
    }
}
